package com.baizhi.service.impl;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.baizhi.entity.Admin;
import com.baizhi.entity.AdminRole;
import com.baizhi.entity.Menu;
import com.baizhi.entity.Role;
import com.baizhi.mapper.AdminRoleMapper;
import com.baizhi.mapper.MenuMapper;
import com.baizhi.service.IAdminRoleService;
import com.baizhi.util.JwtUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author longyang
 * @since 2022-01-13
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {
    @Autowired
    private AdminRoleMapper adminRoleMapper;
    @Autowired
    private MenuMapper menuMapper;
    public Integer addRole(AdminRole adminRole){
        return adminRoleMapper.insert(adminRole);
    }

    @Override
    public List<AdminRole> selectRoleByUser(int userId) {
        //条件构造器：用于构建sql条件
        QueryWrapper<AdminRole> queryWrapper = new QueryWrapper<AdminRole>();
        queryWrapper.eq("admin_id",userId);
        return adminRoleMapper.selectList(queryWrapper);
    }

    @Override
    public Menu selectMenuByUser(int resourceid) {
        //条件构造器：用于构建sql条件
        QueryWrapper<Menu> queryWrapper = new QueryWrapper<Menu>();
        //获取角色所有权限id且查询权限表内的对应id信息并返回
        queryWrapper.eq("menu_id",resourceid);
       Menu menu = menuMapper.selectOne(queryWrapper);
        return menu;
    }

}
